<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <ul id="chatList"></ul>
    <input id="chatMsg" type="text">
    <input id="chatSend" type="button" value="send">

    <script src="Clientjs/jquery-1.11.1.min.js"></script>
    <script>
        var ws = null;
        if(window.WebSocket)
        {
            ws = new WebSocket("ws://127.0.0.1:6999");
            // 建立连接
            ws.onopen=function(){
                console.log("建立连接");
            };
            // 关闭连解
            ws.onclose=function(){
                console.log("关闭连接");
            };
            // 连接出错
            ws.onerror=function(){
                console.log("连接出错");
            };
            $("#chatSend").click(function(){
                var msg = $("#chatMsg").val();
                if(msg.trim().length!=0)
                {
                    ws.send(msg);
                    $("#chatMsg").val("");
                }
                else
                {
                    $("#chatMsg").val("");
                }
            });
            ws.onmessage=function(msg){
                $("<li/>").html(msg.data).appendTo($("#chatList"));
/*                var li = $("<li>"+ msg.data+"</li>");
                $("#chatList").append(li);*/
            };
        }
    </script>
</body>
</html>